package com.daohang361.imqq.ui.autoCompletionField;

import java.awt.Component;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.Icon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
import javax.swing.event.DocumentListener;
import javax.swing.event.ListSelectionListener;

import com.csu.client.module.vo.Cache;
import com.csu.client.module.vo.MsgUser;
import com.daohang361.imqq.resourse.ResourcesManagement;
import com.daohang361.imqq.ui.BaseFrame;
import com.daohang361.imqq.ui.EIMTalkFrame;

class CellRenderer extends JLabel implements ListCellRenderer  {
	 MsgUser user;
	CellRenderer() {
        setOpaque(true);
    }

    public Component getListCellRendererComponent(JList list, Object value,
            int index, boolean isSelected, boolean cellHasFocus) {
        // JOptionPane.showMessageDialog(null, value);
        String userID = (String) value;
        if (value != null) {
            Cache cache=Cache.getInstance();
            MsgUser user=cache.getfriendMap().get(userID);
            this.user=user;
            String headImage=(String)user.getAttribute("headImage");
            Icon icon =ResourcesManagement.getImageIcon("head/"+headImage+".gif",32,32);
            setText(user.getUserName()+"("+userID+")");
            setIcon(icon);
        }
        if (isSelected) {
            setBackground(list.getSelectionBackground());
            setForeground(list.getSelectionForeground());
        } else {
            setBackground(list.getBackground());
            setForeground(list.getForeground());

        }
        return this;
    }
}
